// 计数排序
void CountSort(int* a, int n)
{
    int max, min;
    max = min = a[0];
    for (int i = 0; i < n; i++)
    {
        if (a[i] > max)
            max = a[i];
        if (a[i] < min)
            min = a[i];
    }
    int* table = (int*)malloc(sizeof(int) * (max - min + 1));
    if (table == NULL)
    {
        perror("malloc fail\n");
        return;
    }
    memset(table, 0, sizeof(int) * (max - min + 1));
    for (int i = 0; i < n; i++)
    {
        table[a[i] - min]++;
    }
    int i = 0;
    int j = 0;
    while(j<n)
    {
        
        while (table[i]--)
        {
            a[j++] = i + min;
        }
        i++;
    }
}
